<?php

use Phalcon\Forms\Form;
use Phalcon\Forms\Element\Text;
use Phalcon\Forms\Element\Hidden;
use Phalcon\Forms\Element\Select;
use Phalcon\Validation\Validator\PresenceOf;
use Phalcon\Validation\Validator\Email;

class BusinessUsersForm extends Form
{

    /**
     * Initialize the products form
     */
    public function initialize($entity = null, $options = array())
    {

        if (!isset($options['edit'])) {
            $element = new Text("id");
            $this->add($element->setLabel("Id"));
        } else {
            $this->add(new Hidden("id"));
        }

        $user = new Text("user");
        $user->setLabel("用户");
        $user->setFilters(array('striptags', 'string'));
        $user->addValidators(array(
            new PresenceOf(array(
                'message' => '用户是必填项'
            ))
        ));
        $this->add($user);

		if(isset($options['serverUserId']))
		{
			$serverUserId = new Hidden("serverUserId");
			$serverUserId->setAttribute("value", $options['serverUserId']);
			$this->add($serverUserId);
			
	        $serverUserName = new Text("serverUserName");
            $serverUserName->setLabel('对应平台用户名称');
            $serverUserName->setFilters(array('striptags', 'string'));
		    $serverUserName->setAttribute("value", $options['serverUserName']);
            $serverUserName->setAttribute("readonly", true);
            $serverUserName->addValidators(array(
                new PresenceOf(array(
                    'message' => '对应平台用户名称是必填项'
                ))
            ));
	        $this->add($serverUserName);
        } else {
            $this->add(new Hidden("serverUserId"));
        }
        
        /*
        else
        {
	        $businessSystemId = new Select('serverUserId', ServerUsers::find(), array(
	            'using'      => array('id', 'name'),
	            'useEmpty'   => true,
	            'emptyText'  => '...',
	            'emptyValue' => ''
	        ));
	        $businessSystemId->setLabel('对应平台用户名称');
	        $this->add($businessSystemId);
        }
        */
        
        $businessSystemId = new Select('businessSystemId', BusinessSystems::find(), array(
            'using'      => array('id', 'name'),
            'useEmpty'   => true,
            'emptyText'  => '...',
            'emptyValue' => ''
        ));
        $businessSystemId->setFilters(array('striptags', 'string'));
        $businessSystemId->addValidators(array(
            new PresenceOf(array(
                'message' => '业务系统是必填项'
            ))
        ));
        $businessSystemId->setLabel('业务系统');
        $this->add($businessSystemId);

    }
}